// xc_lshop/shop/gift/index/list.js
var actbill = require('../../model/pack_index')
var app = getApp();

Page({
  mixins: [require('../../../../xc/mixins/basicMixin')],

  /**
   * 页面的初始数据
   */
  data: {
     nav:[],
     navid:'0'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  xcloaddata: function (options, config) {
    // var that=this;
    this.getclass()
    this.getpagelist(this,1)
  },
  getclass() {
    var that=this;
    actbill.getclass().then(obj => {
      that.setData({
        nav:obj
      })
    })
  },
  getpagelist(that, rest, strwhere) {
    if (!strwhere) {
      strwhere = {};
    }
    strwhere["status"] = 1;
    strwhere["bpid"] = this.data.navid;
    if (rest == 1) {
      
      that.setData({ modellist: [] });
    }
    actbill.offset(that, rest, strwhere).then(function (result) {
      var updatemdoel = {};

      if ((result["code"] == "over" && result["obj"]) || result["code"] == "loadmore") {

           
        if (rest == 1) {
          updatemdoel["modellist"] = result["obj"]["modellist"];
        }
        else {
          if (result["obj"]["modellist"].length > 0) {
            updatemdoel["modellist"] = that.data.modellist.concat(result["obj"]["modellist"]);
          }
        }
      }
      wx.stopPullDownRefresh();
      console.log("{updatemdoel}")
      console.log(updatemdoel)
      that.setData(updatemdoel);
     

    });
  },
  onClickNav(e){
    console.log("e")
    console.log(e)
    this.setData({
      navid:e.detail.name
    })
    this.getpagelist(this,1)
  },
  buy(e){
    // console.log("e")
    // console.log(e)
    // return

    var xcmodel=e.currentTarget.dataset.item
    if(xcmodel.num<1){
       wx.showToast({
         icon:"none",
         title: '库存不足',
       })
       return false
    }
    var model={
      activityid:0,
      activityprice:-1,
      attrnameinfo:[],
      attrs:[],
      bpid:0,
      cid:0,
      clubid: -1,
      flag: -1,
      id:xcmodel['id'],
      keyval: xcmodel['id']+"_0_0_-1_3",
      name: xcmodel['name'],
      num: 1,
      price:xcmodel['price'],
      pro_ident:-1,
      proid:xcmodel['id'],
      protype: 3,
      realprice:xcmodel['realprice'],
      simg: xcmodel['simg'],
      weight: 0,
    };

    // console.log("model")
    // console.log(model)

    app.globalData.temcart = {};
    app.globalData.temcart["data"] = [model];
    wx.navigateTo({
      url: '/' + app.globalData.xcsys.m + '/shop/paycore/payinfo?iscart=-1&iscard=1'
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    this.getpagelist(that, -1)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})